<!DOCTYPE html>
<?php 
session_start();
//if(isset($_SESSION["uuid"])){
//    //要求管理员才能访问
//    if($_SESSION["Usertype"]==1){
//        
//    }else{
//      echo "<script>location='shouye.php';</script>";  
//    }
//}else{
//  echo "<script>location='denglu.php';</script>";
//}
$userloged=isset($_SESSION["uid"]);
//?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <form action="gongmingzhe.php" method="get">
            <input type="text" name="k"/><input type="submit" value="搜索"/>
        </form>
        <table border="1px">
            <tr>
                
                <th>编号</th>
                <th>角色名</th>
                <th>图片</th>
                <th>介绍</th>
                 <?php
               if($userloged){
                 echo ' <th></th>';
              }
                ?>
               
            </tr>
         <?php
        require 'common/mysqlCommon.php'; 
        $connect=getConnect();
        $key=isset($_GET["k"])?$_GET["k"]:"";
        $pageSize=3;
        $sqlstr1="select * from gmz where username like '%${key}%' order by uid desc";
       
        $tatalCount=count(getDataSetBySQL($sqlstr1));
        $totalPageCount=intval($tatalCount/$pageSize)+($tatalCount%$pageSize>0?1:0);
//        echo $totalPageCount;
//        echo $tatalCount;
        //对分页参数的处理 分页的参数不能是字符，也不能是负数
        $param_i=isset($_GET["i"])?$_GET["i"]:1;
        $param_i=(int)$param_i;
        //设置分页页码的下限
        $param_i=$param_i<=1?1:$param_i;
        //设置页数页码的上限
      
        $param_i=$param_i>$totalPageCount?$totalPageCount:$param_i;
        $param_i=$param_i>=1?$param_i:1;
        $pageIndex=$param_i-1;
        if($connect){
//            echo "数据库连接成功！";
            //mysqli_set_charset 设置连接使用的字符集
            mysqli_set_charset($connect, "utf-8");
            //mysqli_query 执行sql语句并获得执行结果
            $sqlstring=$sqlstr1." limit ".($pageIndex*$pageSize).",".$pageSize;
//            echo $sqlstring;
            $result=mysqli_query($connect,$sqlstring);
            //mysqli_fetch_array 获取结果集中某一行的记录
            $row=mysqli_fetch_array($result);
            while($row){
                ?>
                <tr>
                    <td><?php echo $row["uid"]; ?></td>
                    <td><?php echo $row["username"]; ?></td>
                    <td><img src="<?php echo $row["tp"]; ?>" style="width:100px;height:100px" /></td>
                    <td><?php echo $row["js"]; ?></td>
                     <?php
                    if($userloged){
                   ?>
                    <td>
                        <a href="caizhi.php?id=<?php echo $row["uid"]; ?>">编辑</a>
                        <a href="caizhi1.php?id=<?php echo $row["uid"]; ?>">删除</a>
                    </td>
                  <?php    
                    }
                    ?>
                </tr>

            <?php
            $row=mysqli_fetch_array($result);
            }
            
        }else{
            echo "数据库连接失败";
        }
        mysqli_close($connect);
        ?>
         </table>
        <hr/>
        <?php
 
       for($temp=1;$temp<=$totalPageCount;$temp++){
          echo " | <a href=\"gongmingzhe.php?i=${temp}\" >第".$temp."页 </a>"; 
       }
        ?>
    </body>
</html>


